﻿using SF.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SF.Ucenter.admin.modeconfig
{
    public partial class modeconfig_edit : SF.Web.UI.ManagePage
    {
        private string action = DTEnums.ActionEnum.Add.ToString(); //操作类型
      
        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = DTRequest.GetQueryString("action");           

            if (!Page.IsPostBack)
            {
                ChkAdminLevel("modeconfig_list", DTEnums.ActionEnum.View.ToString()); //检查权限
                TreeBind(); //绑定类别
                txtSettingName.Attributes.Add("ajaxurl", "../../tools/admin_ajax.ashx?action=setting_name_validate");
            }
        }

        #region 绑定类别
        private void TreeBind()
        {
            BLL.sf_goods_alltype bll = new BLL.sf_goods_alltype();
            DataTable dt = bll.GetList("").Tables[0];

            this.ddlGoodsTypeId.Items.Clear();
            this.ddlGoodsTypeId.Items.Add(new ListItem("请选类型", ""));
            foreach (DataRow dr in dt.Rows)
            {
                string typeNum = dr["typeNum"].ToString();
                string typeName = dr["typeName"].ToString().Trim();
                this.ddlGoodsTypeId.Items.Add(new ListItem(typeName, typeNum));               
            }
        }
        #endregion

        #region 增加操作
        private bool DoAdd()
        {
            try
            {
                Model.manager mgr = Session[DTKeys.SESSION_ADMIN_INFO] as Model.manager;
                Model.sf_modeconfig model = new Model.sf_modeconfig();
                BLL.sf_modeconfig bll = new BLL.sf_modeconfig();

                model.settingNum = "MB" + DateTime.Now.ToString("yyyyMMddhhmmsss");
                model.call_encoding = txtCallConfig.Text.Trim();
                model.goodstype_onshelf = ddlGoodsTypeId.SelectedValue;
                model.settingname = txtSettingName.Text.Trim();
                model.marketing_type =Convert.ToInt32(rblStatus.SelectedValue);              
                model.imgurl = txtImgUrl.Text.Trim();
                model.onshelf = 0;
                model.isdelete = 0;
                model.createman = "";
                model.createtime = DateTime.Now;
                model.remark = txtRemark.Text.Trim();
                model.createman = mgr != null ? mgr.real_name : "";
              
                if (bll.Add(model) > 0)
                {
                    AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加商城模板:" + model.settingname); //记录日志
                    return true;
                }
            }
            catch
            {
                return false;
            }
            return false;
        }
        #endregion

        //保存类别
        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            ChkAdminLevel("modeconfig_list", DTEnums.ActionEnum.Add.ToString()); //检查权限
            if (!DoAdd())
            {
                JscriptMsg("保存过程中发生错误！", "", "Error");
                return;
            }
            JscriptMsg("添加商城模板成功！", "modeconfig_list.aspx");

        }             
    }
}